package com.imooc.common.thread;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created by deng_wb on 2019/8/17
 */
public class ThreadPoolTest {
    public static void main(String[] args) {

        ExecutorService service = Executors.newFixedThreadPool(5); // 定长线程池 execute submit(两种执行方式)

        for (int i = 0; i <6 ; i++) {
            service.execute(()->{
                ThreadUtil.sleep(500);

                System.out.println(Thread.currentThread().getName());
            });
        }

        System.out.println(service);
        service.shutdown(); // 等待所有线程执行完才关闭

        System.out.println(service.isTerminated());
        System.out.println(service.isShutdown());
        System.out.println(service);

        ThreadUtil.sleep(5, TimeUnit.SECONDS);
        System.out.println(service.isTerminated());
        System.out.println(service.isShutdown());
        System.out.println(service);
    }

}
